home *** CD-ROM | disk | FTP | other *** search
- /************************************************************
- *
- * Created: Saturday, May 11, 1991 12:55:02 PM
- * CNeoPersist.h
- * Definitions for a persistent object class
- *
- *
- * Copyright © Neologic Systems 1992-1994. All Rights Reserved.
- * All rights reserved
- *
- *
- * Object persistence and integrity is provided by the CNeoPersist class. Persistent
- * objects are first class citizens. A newly created persistent object is created
- * through the use of the new operator. The object can be made permanent by using
- * the database's addObject method. This associates the object with a database and assigns it
- * an identity. Identity is simply a value that, in conjunction with with the class
- * of the object, can be used find the object in the database. In order to unambiguously
- * refer to it, an object should have a unique identity within its class within its
- * database. In some situations ambiguity may be desirable, so finding all objects of a
- * given base class having a given identity is supported.
- *
- * Typically, permanent objects are sorted within their class in ascending ID
- * order. This allows the use of binary searches to locate objects given a ID
- * value. However custom indexing strategies are also supported.
- *
- * The method remove() breaks the association between object and database.
- *
- * The unrefer() method of persistent objects supports the object's
- * reference count mechanism. This method decrements the reference count. If the count
- * goes to zero and the object is not locked, then the object is purgeable. Purgeable
- * objects can be freed during purging. Purging, which is usually invoked from the
- * application's GrowZone routine, involves traversing the class and free lists
- * freeing purgeable objects until a large enough node of memory is found.
- *
- * The impact of this referential integrity and transparent persistence mechanism
- * should be considered from a number of different perspectives. From a memory
- * standpoint, the CNeoPersist class adds 16 bytes to the size of every persistent
- * object. The overhead of maintaining the indexes and class lists in memory typically
- * adds an additional 12 bytes per permanent object. However, these numbers are offset
- * by several factors. From a memory usage standpoint, this mechanism is very
- * agressive about minimizing its memory footprint by purging when memory is needed.
- * From a performance perspective, the system is optimally fast at locating objects.
- * And finally from the point of view of the developer, the visible complexity of the
- * system is greatly reduced by integrating object persistence into the framework.
- *
- ***********************************************************/
- #pragma once /* Include this file only once */
- #ifndef __CNeoPersist__
- #define __CNeoPersist__ 1
-
- #include "NeoTypes.h"
- #include <AERegistry.h>
-
- #ifdef CNeoPersistBaseH
- #include CNeoPersistBaseH
- #endif
-
- class CNeoMetaClass;
- class CNeoDatabase;
- class CNeoContainerStream;
-
- class CNeoPersist
- {
- public:
- /** Instance Methods **/
- void * operator new(size_t aSize);
- void operator delete(void *aObject, size_t aSize);
- static void * CacheMalloc(size_t aSize);
- CNeoPersist(void);
- virtual ~CNeoPersist(void); // Just so that destructors are all virtual
- static CNeoPersist *New(void);
- virtual NeoID getClassID(void) const;
- void getClassName(CNeoString &aName) const;
- virtual long getFileLength(void) const;
- CNeoMetaClass * getMetaClass(void) const;
- virtual CNeoSelect *getUniqueKey(void);
- virtual OSErr getValue(const NeoTag aName, const NeoTag aType, void *aValue);
- virtual OSErr setValue(const NeoTag aName, const NeoTag aType, const void *aValue);
- static OSErr ConvertType(const void *aSource, const NeoTag aSourceType, void *aDest, const NeoTag aDestType);
-
- /** I/O Methods **/
- virtual void readObject(CNeoStream *aStream, const NeoTag aTag);
- virtual void writeObject(CNeoStream *aStream, const NeoTag aTag);
- virtual Boolean commit(CNeoContainerStream *aStream, const Boolean aCompletely, const Boolean aCompress, const Boolean aDeeply);
-
- /** Searching Methods **/
- static void * FindByID(CNeoDatabase *aDatabase, const NeoID aClassID, const NeoID aID, const Boolean aDeeply, NeoTestFunc1 aFunc = nil, void *aParam = nil, const NeoLockType aLock = kNeoDefaultLock);
- static void * FindEvery(CNeoDatabase *aDatabase, const NeoID aClassID, const Boolean aDeeply, NeoTestFunc1 aFunc = nil, void *aParam = nil, const NeoLockType aLock = kNeoDefaultLock);
-
- /** Tree Management Methods **/
- virtual void forgetChild(CNeoPersist *aChild);
- virtual void forgetChildren(const short aIndex);
- CNeoPersist * getParent(void) const {return fParent;}
- static Boolean IsLeaf(const NeoMark aMark);
- void setParent(CNeoPersist *aParent) {fParent = aParent;}
- virtual void setSubtree(CNeoNode *aOldRoot, CNeoNode *aNewRoot);
-
- /** Persistence Methods **/
- virtual void add(void);
- NeoMark getMark(void) const {return fMark;}
- NeoID getID(void) const {return fID;}
- NeoVersion getVersion(void) const {return fVersion;}
- Boolean isDirty(void) const {return (Boolean)(fDirty != kNeoClean);}
- Boolean isTemporary(void) const {return fTemporary;}
- virtual void remove(void);
- virtual void relocate(const NeoMark aNewMark);
- void setDirty(const NeoDirty aReason = kNeoChanged);
- virtual void setID(const NeoID aID);
- virtual void update(CNeoPersist *aObject);
-
- /** Concurrency Methods **/
- NeoRefCnt getRefCnt(void) const {return fRefCnt;}
- void referTo(void);
- NeoRefCnt unrefer(void);
- void autoReferTo(void);
- NeoRefCnt autoUnrefer(void);
- void setBusy(void);
- void setUnbusy(void);
- void autoBusy(void);
- void autoUnbusy(void);
- static NeoCheckpoint
- GetCheckpoint(void);
- static void ResetCheckpoint(const NeoCheckpoint aCheckPoint);
-
- /** Purge Methods **/
- virtual Boolean isPurgeable(NeoSize *aNeeded);
- virtual Boolean purge(NeoSize *aNeeded);
-
- #ifdef qNeoDebug
- /** Debugging Methods **/
- virtual const void *verify(const void *aValue) const;
- #endif
-
- /** Instance Variables **/
- public:
- NeoID fID; // Identity of the object
- Boolean fLeaf : 1; // not an inode?
- Boolean fRoot : 1; // node is the root of the tree?
- Boolean fTemporary : 1; // is a temporary object?
- Boolean fLocal : 1; // is locally visible only?
- Boolean fShareFill : 2; // Reserved for use by NeoShare
- Boolean fBusy : 1; // this node is being manipulated, don't change it!
-
- protected:
- Boolean fBool1 : 1; // spare boolean for use by subclasses of CNeoPersist
-
- Boolean fBool2 : 1; // spare boolean for use by subclasses of CNeoPersist
- Boolean fBool3 : 1; // spare boolean for use by subclasses of CNeoPersist
- Boolean fReserved : 2; // Rest of byte reserved by NeoLogic for future use
- public:
- NeoDirty fPeerDirty : 2; // peer needs to be updated with state of this object?
- NeoDirty fDirty : 2; // Memory state different than file state
- protected:
-
- public:
- NeoVersion fVersion; // the object version number
- NeoMark fMark; // Location of object in database
- CNeoPersist * fParent; // Back pointer to this class's containing
- NeoRefCnt fRefCnt; // Purgeable when zero
-
- static long FCacheSize; // Maximum size of the object cache
- static long FCacheUsed; // Amount of space in cache being used
- static long FPurgeStart; // Amount of space in cache as purge begins
- static short FPurgeDesperation; // How desperate are we to find free memory?
- static void * FReserve; // Pointer to a rainy-day memory reserve
- static NeoReferTable *
- FReferTable;
- static unsigned short
- FReferTableIndex;
- static NeoBusyTable *
- FBusyTable;
- static unsigned short
- FBusyTableIndex;
- };
-
- const NeoTag pNeoFlags = Neo4CharConst('NP', 'fl');
- const NeoTag pNeoTemporary = Neo4CharConst('NP', 'tm');
- const NeoTag pNeoLocal = Neo4CharConst('NP', 'lo');
- const NeoTag pNeoBusy = Neo4CharConst('NP', 'bz');
- const NeoTag pNeoDirty = Neo4CharConst('NP', 'dy');
- const NeoTag pNeoRefCnt = Neo4CharConst('NP', 'rc');
-
- #include <AEObjects.h>
- enum {kNeoPersistFileLength = 2 + sizeof(NeoVersion)};
- #endif
-